/* 
 * File:   Term.cpp
 * Author: taylor
 * 
 * Created on November 7, 2012, 2:27 PM
 */

#include "Term.h"

Term::Term() {
}


/**
 * Term constructor
 * @param term string to set as the term
 */
Term::Term(string term) {
    setTerm(term);
}

/**
 * Term getter
 * @return the term as a string
 */
string Term::getTerm() const {
    return _term;
}

/**
 * Set the term
 * @param term string to set as term
 */
void Term::setTerm(string term) {
    _term = term;
}

/**
 * Add an occurance for a certain document ID
 * @param docID
 */
void Term::addOccuranceInDocument(const int docID) {
    map<int, int>::iterator found = _foundInDocuments.find(docID);

    if (found == _foundInDocuments.end()) {
        _foundInDocuments.insert(pair<int, int> (docID, 1));
    } else {
        (found->second) += 1;
    }
}

/**
 * Get the map of document occurances
 * @return ptr to map<int (document ID), int (number of times this term occurs)>
 */
map<int, int>* Term::getDocumentOccurances() {
    return &_foundInDocuments;
}

/**
 * Overloaded < operator
 * @param rgt
 * @return 
 */
bool Term::operator<(Term &rgt) {
    return _term < rgt.getTerm();
}

Term::~Term() {
}

